Imports Microsoft.VisualBasic
Imports System.Data.Common
Imports System.Configuration
Imports System.Collections
Imports MySql.Data.MySqlClient
Imports System.Web.UI
Imports System.Collections.Generic

Public Class GenHelper


    Public Overloads Shared Function ExecuteScalar(ByVal SqlComm As String, ByVal SqlConn As String) As Object

        Dim Value As Object

        'SqlConn = ConfigurationManager.ConnectionStrings.Item("MySqlConnString").ToString()

        Value = MySqlHelper.ExecuteScalar(SqlConn, SqlComm)

        Return (Value)

    End Function

    Public Overloads Shared Function ExecuteScalar(ByVal SqlComm As String, ByVal CommandParameters() As GenParameter, ByVal SqlConn As String) As Object

        Dim Value As Object
        Dim Params(CommandParameters.Length - 1) As MySqlParameter
        Dim P As New GenParameter
        Dim count As Integer

        count = 0

        'Populate the MySqlParameters
        For Each P In CommandParameters
            Params(count) = New MySqlParameter()
            Params(count).ParameterName = CommandParameters(count).ParameterName
            Params(count).Value = CommandParameters(count).Value
            Params(count).DbType = CommandParameters(count).DbType
            count = count + 1
        Next

        Value = MySqlHelper.ExecuteScalar(SqlConn, SqlComm, Params)

        Return Value

    End Function
    Public Overloads Shared Function ExecuteNonQuery(ByVal SqlComm As String, ByVal CommandParameters() As GenParameter, ByVal SqlConn As String) As Integer

        Dim Value As Object
        Dim Params(CommandParameters.Length - 1) As MySqlParameter
        Dim P As New GenParameter
        Dim count As Integer

        count = 0

        'Populate the MySqlParameters
        For Each P In CommandParameters
            Params(count) = New MySqlParameter()
            Params(count).ParameterName = CommandParameters(count).ParameterName
            Params(count).Value = CommandParameters(count).Value
            Params(count).DbType = CommandParameters(count).DbType
            count = count + 1
        Next

        Value = MySqlHelper.ExecuteNonQuery(SqlConn, SqlComm, Params)

        Return Value

    End Function

    Public Overloads Shared Function ExecuteNonQuery(ByVal SqlComm As String, ByVal SqlConn As String) As Integer

        Dim Value As Object

        Value = MySqlHelper.ExecuteNonQuery(SqlConn, SqlComm)

        Return (Value)

    End Function

    Public Overloads Shared Function ExecuteReader(ByVal SqlComm As String, ByVal SqlConn As String) As DbDataReader

        Dim Reader As DbDataReader

        Reader = MySqlHelper.ExecuteReader(SqlConn, SqlComm)

        Return (Reader)

        Reader.Close()

    End Function

    Public Overloads Shared Function ExecuteReader(ByVal SqlComm As String, ByVal CommandParameters() As GenParameter, ByVal SqlConn As String) As DbDataReader

        Dim Reader As DbDataReader
        Dim Params() As MySqlParameter
        Dim P As New GenParameter
        Dim count As Integer

        count = 0
        ReDim Params(CommandParameters.Length - 1)
        'Populate the MySqlParameters
        For Each P In CommandParameters
            Params(count) = New MySqlParameter()
            Params(count).ParameterName = CommandParameters(count).ParameterName
            Params(count).Value = CommandParameters(count).Value
            Params(count).DbType = CommandParameters(count).DbType
            count = count + 1
        Next

        Reader = MySqlHelper.ExecuteReader(SqlConn, SqlComm, Params)

        Return Reader

        Reader.Close()

    End Function

    Public Shared Function GiveFactory() As DbProviderFactory
        Dim Provider As String
        Provider = ConfigurationManager.AppSettings("MySqlProvider")

        Return DbProviderFactories.GetFactory(Provider)
    End Function

End Class
